<?php

namespace Managers;

class Locales extends BaseManager
{

    protected $__table = '\Catalog\Locales';

    public function getByLocale($locale)
    {
        $res = $this->_em->createQueryBuilder()
                ->select('l', 'partial pages.{id, title}')
                ->from($this->__table, 'l')
                ->join('l.pages', 'pages')
                ->where('l.locale = :locale')->setParameter('locale', $locale)
                ->getQuery()
                ->getArrayResult();

        return $res[0]['pages'];

    }

    public function qb()
    {
        $qb = $this->_em->getRepository($this->__table)->createQueryBuilder('c');
        return $qb;
    }

    public function getByLocaleName($locale) {

        $res = $this->_em->createQueryBuilder()
                 ->select('loc')
                ->from($this->__table, 'loc')
                ->where('loc.locale = :name')->setParameter('name', $locale)
                ->setMaxResults(1)
                ->getQuery()
                ->getArrayResult();

        return count($res)? $res[0] : false;
    }

}
